package org.example.base.websocket.controller;

import org.example.base.websocket.service.WebSocketService;
import org.example.core.enums.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 * Date: 2024/1/20 01:26
 */
@RequestMapping
@RestController
public class WebSocketController {

    @Autowired
    private WebSocketService webSocketService;

    /**
     * 消除未读消息
     * @param currentUserId
     * @param toConnectUserId
     * @return
     */
    @PutMapping("/chat/read")
    public ApiResult readMessage(@RequestParam("currentUserId") String currentUserId,
                                 @RequestParam("toConnectUserId") String toConnectUserId){
        webSocketService.readMessage(currentUserId,toConnectUserId);
        return ApiResult.success();
    }

    /**
     * 查看联系人列表
     * @param currentUserId
     * @return
     */
    @GetMapping("/chat/getContactList")
    public ApiResult getContactList(@RequestParam("currentUserId")String currentUserId){
        return ApiResult.success(webSocketService.getContactList(currentUserId));
    }

    /**
     * 查询最近聊天记录
     * @param currentUserId
     * @param toConnectUserId
     * @return
     */
    @GetMapping("/chat/getRecentChatMsg")
    public ApiResult getRecentChatMsg(@RequestParam("currentUserId") String currentUserId,
                                      @RequestParam("toConnectUserId") String toConnectUserId){
        return ApiResult.success(webSocketService.getRecentChatMsg(currentUserId,toConnectUserId));
    }
}
